package com.pt25.service.sys.domain.config.service.impl;

import com.pt25.base.util.PageUtil;
import com.pt25.service.sys.domain.config.ddo.ConfigData;
import com.pt25.service.sys.domain.config.ddo.ConfigLog;
import com.pt25.service.sys.domain.config.ddo.ConfigValue;
import com.pt25.service.sys.domain.config.service.ConfigLogService;
import com.pt25.service.sys.repository.mysql.persistence.ConfigLogRepo;
import com.pt25.service.sys.repository.mysql.po.ConfigLogPo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ConfigLogServiceImpl implements ConfigLogService {
  @Resource
  private ConfigLogRepo configLogRepo;

  @Override
  public Long addConfigLog(ConfigData configData , ConfigValue configValue, String manipulateType) {
    ConfigLogPo configLogPo = ConfigLogPo.builder()
            .configValueId(configValue.getId())
            .dataKey(configData.getDataKey())
            .valueKey(configValue.getValueKey())
            .valueContent(configValue.getValueContent() + "")
            .manipulateType(manipulateType).build();
    configLogRepo.save(configLogPo);
    return configLogPo.getId();
  }

  @Override
  public ConfigLog getConfigLog(Long id) {
    return ConfigLog.toConfigLog(configLogRepo.getById(id));
  }

  @Override
  public PageUtil.PageVo pageConfigLog(ConfigLog configLog) {
    return configLogRepo.pageConfigLog(configLog);
  }
}
